﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using dtSearch.Engine;

namespace DTSearchHelper
{
    public class ErrorHelper
    {
        public ErrorHelper(int code)
        {
            this.errorCode = code;
            this.errorMessage = ((ErrorCodes)this.errorCode).ToString();
            DataTable dt = ErrorHelper.getErrorTable();
            this.errorDescription = dt.Select("Code=" + this.errorCode)[0]["Description"].ToString();
        }

        private int errorCode = -1;
        public int ErrorCode
        {
            get { return errorCode; }
        }


        private string errorMessage = "";
        public string Errormessage
        {
            get { return errorMessage; }
        }

        private string errorDescription = "";
        public string ErrorDescription
        {
            get { return errorDescription; }
        }

        private static DataTable getErrorTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Code", typeof(int));
            dt.Columns.Add("Description");
            dt.Rows.Add(1, "The dtSearch Engine could not access an index");
            dt.Rows.Add(3, "A temporary file could not be opened");
            dt.Rows.Add(5, "An attempt was made to open an index created by an incompatible version of dtSearch");
            dt.Rows.Add(7, "A directory (the home or private directory during initialization) could not be accessed");
            dt.Rows.Add(8, "The private directory could not be locked");
            dt.Rows.Add(9, "A file could not be accessed, either because it was not present or because it was locked in a way that prevented the dtSearch Engine from accessing it");
            dt.Rows.Add(10, "A file could not be accessed because it appears to be damaged, causing a file parsing error");
            dt.Rows.Add(11, "The index has reached the maximum size for an index");
            dt.Rows.Add(13, "Operation timed out (trigged by TimeoutSeconds)");
            dt.Rows.Add(17, "A file could not be accessed because it is encrypted");
            dt.Rows.Add(116, "The search request provided to the dtSearch Engine contained one or more syntax errors");
            dt.Rows.Add(120, "The search was stopped due to the AutoStopLimit setting (too many documents were found)");
            dt.Rows.Add(122, "No files were retrieved in a search");
            dt.Rows.Add(135, "The search request was longer than 32,000 bytes");
            dt.Rows.Add(137, "A search request matched too many unique words in an index");
            dt.Rows.Add(159, "There is not enough disk space to continue indexing");
            dt.Rows.Add(177, "The index could not be locked for update due to an \"Access Denied\" error. This means that either (1) the folder's security settings do not permit write access for the user performing the update, or (2) another user or process was updating the index");
            dt.Rows.Add(201, "Unable to connect to data source during indexing");
            dt.Rows.Add(202, "Unable to access cached document in index");
            dt.Rows.Add(203, "Index update could not complete due to an error accessing the index");

            return dt;
        }
    }
}
